﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Silmoon.Threading;
using cklib;

namespace Cooky.Client.DomainDir
{
    public partial class DomainForm : Silmoon.Windows.Forms.GenieForm
    {
        public bool SucessState = false;
        cklib.CookyDNSAPI cooky = null;
        public DomainForm(cklib.CookyDNSAPI cooky)
        {
            this.cooky = cooky;
            InitializeComponent();
        }

        private void ctlCancelButton_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void ctlSubmitButton_Click(object sender, EventArgs e)
        {
            Threads.ExecAsync(delegate()
            {
                CookyResult result = cooky.CreateDomain(ctlDomainTextBox.Text);
                this.Invoke(new tmpHander(delegate()
                {
                    if (result.Success)
                    {
                        SucessState = true;
                        Close();
                    }
                    else
                    {
                        MessageBox.Show("创建域名错误" + Translate.TranslateIt(result.Message) + "！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }));
            }, null);
        }

        protected override void OnFormClosing(FormClosingEventArgs e)
        {
            panel1.Visible = false;
            base.OnFormClosing(e);
        }

        void hideThis()
        {
            panel1.Visible = false;
            HideEx();
        }

        private void DomainForm_Shown(object sender, EventArgs e)
        {
            FormGenieExtension.ShowControl(ctlCancelButton);
            FormGenieExtension.ShowControl(ctlSubmitButton, true, 200);
        }
    }
}
